package tr.edu.ege.kipler.satisfiability.clash;

import java.util.HashSet;
import java.util.Set;

import tr.edu.ege.kipler.satisfiability.container.ABox;
import tr.edu.ege.kipler.satisfiability.container.DependencyManager;
import tr.edu.ege.kipler.satisfiability.container.WorldConstraintSystem;
import tr.edu.ege.kipler.syntax.atomicformula.ConceptAssertion;
import tr.edu.ege.kipler.syntax.atomicformula.Formula;

/**
 * 
 * @author İnanç Seylan
 *
 */
public class BasicClashDetectionStrategy implements ClashDetectionStrategy {

	private String explanation;

	private Set<WorldConstraintSystem> dependencySet = new HashSet<WorldConstraintSystem>();

	public Set<WorldConstraintSystem> getDependencySet() {
		return dependencySet;
	}

	public boolean hasClash(ABox abox, Formula formula) {
		boolean hasClash = false;
		if (formula instanceof ConceptAssertion) {
			ConceptAssertion ca = (ConceptAssertion) formula;
			ConceptAssertion negCa;
			negCa = (ConceptAssertion) ca.copy().toggleNegated();
			hasClash = abox.contains(negCa);
			if (hasClash) {
				dependencySet.clear();
				DependencyManager depMan = abox.getWorld().getWcs().getData()
						.getDependencyManager();
				dependencySet.addAll(depMan.getDependencies(ca));
				dependencySet.addAll(depMan.getDependencies(negCa));
				explanation = ca + " and its negation";
			}
		}
		return hasClash;
	}

	public String getExplanation() {
		return explanation;
	}

}
